home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_se / switch_collection.e < prev    next >
Text File  |  1998-12-22  |  5KB  |  209 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. expanded class SWITCH_COLLECTION
  17.    -- 
  18.    -- Unique Global Object in charge of the `switch_collection'.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.  
  25.    dictionary: DICTIONARY[DICTIONARY[RUN_FEATURE,STRING],STRING] is
  26.      -- First STRING key is the name of a run type corresponding 
  27.      -- to a RUN_CLASS.
  28.          -- Embedded dictionary gives all switching points.
  29.       once
  30.      !!Result.make;
  31.       end;
  32.  
  33. feature {CALL_PROC_CALL}
  34.  
  35.    update(target: EXPRESSION; run_feature: RUN_FEATURE) is
  36.       -- Update the switch_collection such that `run_feature' can be 
  37.       -- applied with `target'.
  38.       require
  39.      target /= Void;
  40.      run_feature /= Void
  41.       local
  42.      current_type: TYPE;
  43.      running: ARRAY[RUN_CLASS];
  44.       do
  45.      if target.is_current then
  46.      elseif target.is_manifest_string then
  47.      else
  48.         current_type := run_feature.current_type;
  49.         if current_type.is_reference then
  50.            running := current_type.run_class.running;
  51.            if running /= Void and then running.count > 1 then
  52.           update_with(run_feature);
  53.            end;
  54.         end;
  55.      end;
  56.       end;
  57.  
  58. feature {C_PRETTY_PRINTER}
  59.  
  60.    c_define is
  61.      -- Produce C code for switches.
  62.       local
  63.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  64.      count1, count2, total: INTEGER;
  65.      switch: SWITCH;
  66.       do
  67.      if not dictionary.empty then
  68.         cpp.swap_on_c;
  69.         cpp.split_c_now;
  70.         from  
  71.            count1 := 1;
  72.         until
  73.            count1 > dictionary.count
  74.         loop
  75.            dictionary2 := dictionary.item(count1);
  76.            from  
  77.           count2 := 1;
  78.            until
  79.           count2 > dictionary2.count
  80.            loop
  81.           switch.c_define(dictionary2.item(count2));
  82.           total := total + 1;
  83.           cpp.incr_elt_c_count(20);
  84.           count2 := count2 + 1;
  85.            end;
  86.            count1 := count1 + 1;
  87.         end;
  88.      end;
  89.      echo.print_count("Defined Switche",total);
  90.       end;
  91.  
  92. feature {SMALL_EIFFEL}
  93.  
  94.    falling_down is
  95.       local
  96.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  97.      count1, count2: INTEGER;
  98.       do
  99.      if not dictionary.empty then
  100.         from  
  101.            count1 := 1;
  102.         until
  103.            count1 > dictionary.count
  104.         loop
  105.            dictionary2 := dictionary.item(count1);
  106.            from  
  107.           count2 := 1;
  108.            until
  109.           count2 > dictionary2.count
  110.            loop
  111.           dictionary2.item(count2).fall_down;
  112.           count2 := count2 + 1;
  113.            end;
  114.            count1 := count1 + 1;
  115.         end;
  116.      end;
  117.       end;
  118.  
  119. feature {CECIL_POOL}
  120.  
  121.    update_with(run_feature: RUN_FEATURE) is
  122.       require
  123.      run_feature /= Void
  124.       local
  125.      current_type: TYPE;
  126.      key1, key2: STRING;
  127.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  128.      running: ARRAY[RUN_CLASS];
  129.       do
  130.      current_type := run_feature.current_type;
  131.      running := current_type.run_class.running;
  132.      if running /= Void and then running.count > 1 then
  133.         key1 := current_type.run_time_mark;
  134.         key2 := run_feature.name.to_key;
  135.         if dictionary.has(key1) then
  136.            dictionary2 := dictionary.at(key1);
  137.            if not dictionary2.has(key2) then
  138.           dictionary2.put(run_feature,key2);
  139.            end;
  140.         else
  141.            !!dictionary2.make;
  142.            dictionary2.put(run_feature,key2);
  143.            dictionary.put(dictionary2,key1);
  144.         end;
  145.         check
  146.            dictionary.at(key1).at(key2) = run_feature
  147.         end;
  148.      end;
  149.       end;
  150.  
  151. feature {C_PRETTY_PRINTER}
  152.  
  153.    remove(run_feature: RUN_FEATURE) is
  154.       require
  155.      run_feature /= Void
  156.       local
  157.      current_type: TYPE;
  158.      key1, key2: STRING;
  159.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  160.       do
  161.      current_type := run_feature.current_type;
  162.      key1 := current_type.run_time_mark;
  163.      if dictionary.has(key1) then
  164.         dictionary2 := dictionary.at(key1);
  165.         key2 := run_feature.name.to_key;
  166.         dictionary2.remove(key2);
  167.         check
  168.            not dictionary.at(key1).has(key2)
  169.         end;
  170.      end;
  171.       end;
  172.  
  173. feature {JVM}
  174.  
  175.    jvm_define is
  176.      -- Produce Java byte code for switches.
  177.       local
  178.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  179.      count1, count2, total: INTEGER;
  180.      switch: SWITCH;
  181.      up_rf: RUN_FEATURE;
  182.       do
  183.      if not dictionary.empty then
  184.         from  
  185.            count1 := 1;
  186.         until
  187.            count1 > dictionary.count
  188.         loop
  189.            dictionary2 := dictionary.item(count1);
  190.            from  
  191.           count2 := 1;
  192.            until
  193.           count2 > dictionary2.count
  194.            loop
  195.           up_rf := dictionary2.item(count2);
  196.           jvm.set_current_frame(up_rf);
  197.           switch.jvm_define(up_rf);
  198.           total := total + 1;
  199.           count2 := count2 + 1;
  200.            end;
  201.            count1 := count1 + 1;
  202.         end;
  203.      end;
  204.      echo.print_count("Defined Switche",total);
  205.       end;
  206.    
  207. end -- SWITCH_COLLECTION
  208.  
  209.